<template>
  <div class="rank">
    <back-nav title="排行榜分类"></back-nav>

    <my-scroll class="scroll-box">
      <div class="box">

      <div class="container">

        <div
          class="list-item"
          v-for="(item, index) in allList"
          :key="index"
          @click="selectRank(item.name)">
          <div class="list-image">
            <img :src="item.coverImgUrl">
          </div>
          <div class="list-tracks">
            <span v-for="(item2, index) in item.tracks" :key="index">
              {{index+1}}. {{item.tracks.length !== 0?item2.first:'---'}}
            </span>
            <div class="list-description" v-if="item.tracks.length === 0">
              <span class="name">{{item.name}}</span>
              <span class="description">{{item.description}}</span>
            </div>
          </div>
        </div>

      </div>

      </div>
    </my-scroll>
  </div>
</template>

<script>
  import BackNav from "../components/BackNav";
  import MyScroll from "../components/MyScroll";
  export default {
    name: "AllRank",
    components: {
      BackNav,
      MyScroll
    },
    data(){
      return {
        rankLimit: 20, /** 获取的列表数量限制 */
        allList: []
      };
    },
    methods: {
      initAllRank(){
        this.$axios.get('/api/toplist/detail')
          .then(res => {
            this.allList = res.data.list.slice(0,this.rankLimit);
          })
          .catch(err => console.log(err));
      },
      selectRank(name){
        this.$router.push({
          name: 'rank',
          params: {
            topListName: name
          }
        });
      }
    },
    activated(){
      if(!this.$route.meta.isBack || this.isFirstEnter){
        this.initAllRank();
      }
      this.$route.meta.isBack=false;
      this.isFirstEnter = false;
    },
    mounted() {
      this.isFirstEnter = true;
    }
  }
</script>

<style scoped lang="scss">
  .rank{
    width: 100%;
    box-sizing: border-box;
    padding-bottom: 100px;
    position: absolute;
    top: 0;
    left: 0;
    background-image: $dark-gradient-backgroud;
    background-attachment: fixed;
    .scroll-box{
      width: 100%;
      height: 100vh;
      overflow: auto;
      .box{
        padding-top: 50px;
        padding-bottom: 80px;
      }
    }
    .container{
      width: 100vw;
      height: auto;
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      align-items: center;
      .list-item{
        width: 94vw;
        height: 25vw;
        display: flex;
        align-items: center;
        border-bottom: 1px solid lightgreen;
        .list-image{
          width: 22vw;
          height: 22vw;
          img{
            width: 22vw;
            height: 22vw;
            border-radius: 2vw;
          }
        }
        .list-tracks{
          margin-left: 4vw;
          max-width: 70vw;
          height: 20vw;
          font-size: 0.26rem;
          color: $dark-color2;
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          span{
            max-width: 100%;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
          }
          .list-description{
            display: flex;
            height: 20vw;
            flex-direction: column;
            justify-content: space-around;
            .name{
              max-width: 100%;
              white-space: nowrap;
              text-overflow: ellipsis;
              overflow: hidden;
            }
            .description{
              width: 100%;
              text-overflow: ellipsis;
              overflow: hidden;
            }
          }
        }
      }
    }
  }


</style>